﻿using ArchiSimple.Windows.ViewModel;
using ArchiSimple.Windows.ViewModel.PlanObjects;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Xunit;

namespace ArchiSimple.Windows.Test
{
    public static class TestHelper
    {
        public static void AddWall(this PlanViewModel viewModel, double x1, double y1, double x2, double y2)
        {
            Assert.Equal(PlanViewModel.PlanMode.SelectPlanObject, viewModel.Mode);

            viewModel.AddWallCommand.Execute(null);

            Assert.Equal(PlanViewModel.PlanMode.AddWall, viewModel.Mode);

            // Add begin point.
            viewModel.MousePoint = new System.Windows.Point(x1, y1);
            viewModel.UpPlanCommand.Execute(null);

            Assert.NotNull(viewModel.WallGeometry);
            Assert.Equal(PlanViewModel.PlanMode.AddWall, viewModel.Mode);

            // Cursor move.
            viewModel.MousePoint = new System.Windows.Point(x2, y2);
            viewModel.PreviewWallCommand.Execute(null);

            Assert.NotNull(viewModel.WallGeometry);
            Assert.Equal(PlanViewModel.PlanMode.AddWall, viewModel.Mode);

            // Add end point.
            viewModel.UpPlanCommand.Execute(null);

            Assert.NotNull(viewModel.WallGeometry);
            Assert.Equal(PlanViewModel.PlanMode.SelectPlanObject, viewModel.Mode);
        }

        public static void MovePoint(this PlanViewModel viewModel, RoomViewModel point, int x, int y)
        {

            viewModel.MovePoint(point, 0, 0, x, y);
        }
        
        public static void MovePoint(this PlanViewModel viewModel, PointViewModel point, int x, int y)
        {
            viewModel.MovePoint(point, point.X, point.Y, x, y);
        }

        public static void MovePoint(this PlanViewModel viewModel, PlanObjectViewModel point, double srcX, double srcY, int x, int y)
        {
            Assert.Equal(PlanViewModel.PlanMode.SelectPlanObject, viewModel.Mode);
            viewModel.CurrentPlanObject = point;
            Assert.Equal(PlanViewModel.PlanMode.SelectPlanObject, viewModel.Mode);
            viewModel.MousePoint = new System.Windows.Point(srcX + 1000, srcY + 1000);
            Assert.Equal(PlanViewModel.PlanMode.SelectPlanObject, viewModel.Mode);
            viewModel.DownPlanCommand.Execute(null);
            Assert.Equal(PlanViewModel.PlanMode.MovePlanObject, viewModel.Mode);
            viewModel.MousePoint = new System.Windows.Point(x + 1000, y + 1000);
            Assert.Equal(PlanViewModel.PlanMode.MovePlanObject, viewModel.Mode);
            viewModel.PreviewWallCommand.Execute(null);
            Assert.Equal(PlanViewModel.PlanMode.MovePlanObject, viewModel.Mode);
            viewModel.UpPlanCommand.Execute(null);
            Assert.Equal(PlanViewModel.PlanMode.SelectPlanObject, viewModel.Mode);
        }
    }
}
